<!--
 * @Author: fishroom
 * @Date: 2021-08-23 22:37:59
 * @LastEditTime: 2021-09-02 09:17:36
 * @FilePath: \backstage\src\components\content\input\InputItem.vue
-->
<template>
  <div class="input-box">
    <div class="input-item">
      <input
        type="text"
        name=""
        class="ipt-item"
        placeholder="全部"
        :value="value"
        @click="isFlag()"
      />
      <span class="iconfont pull-down">&#xe601;</span>
      <span class="triangle" v-show="flag"></span>
    </div>
    <div class="showInput" v-if="List.length > 0" v-show="flag">
      <ul class="input-pad">
        <li
          class="select-item text-center"
          v-for="(item, index) in List"
          :key="index"
          @click="activeClick(index, $event, item.id)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: "InputItem",
  data() {
    return {
      count: 0,
      value: "",
      flag: false
    };
  },
  props: {
    List: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  methods: {
    activeClick(index, e, id) {
      this.value = e.target.innerHTML;
      this.count = index;
      this.flag = false;
      this.$emit("tabClick", index, e.target.innerHTML, id);
    },
    isFlag() {
      this.flag = !this.flag;
    }
  }
};
</script>

<style lang="scss">
.input-box {
  position: relative;
  max-width: 50%;
  min-width: 20px;
}

.input-item {
  display: inline-block;
  position: relative;
  line-height: 40px;
  cursor: pointer;
}

.ipt-item {
  padding-right: 30px;
  max-width: 100%;
  min-width: 20px;
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: none;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  cursor: pointer;
  &:hover {
    border-color: #c0c4cc;
  }
  &:focus {
    border-color: #409eff;

    & + .pull-down {
      transform: rotate(-90deg);
    }
  }
}

.pull-down {
  position: absolute;
  height: 100%;
  right: 8px;
  top: 0;
  text-align: center;
  color: #c0c4cc;
  transition: all 0.3s;
  transform: rotate(90deg);
  pointer-events: none;
  cursor: pointer;
}

.showInput {
  position: absolute;
  top: 50px;
  left: 0;
  width: 100%;
  height: 170px;
  overflow-y: auto;
  z-index: 99;
  border-radius: 4px;
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

  /*滚动条样式*/
  &::-webkit-scrollbar {
    width: 4px;
    height: 5px;
    background-color: #dcdfe6;
  }

  //滚动条里面的小方块
  &::-webkit-scrollbar-thumb {
    border-radius: 5px;
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
    background: rgba(77, 76, 76, 0.2);
  }

  //滚动条的轨道
  &::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.1);
  }
}

.triangle {
  top: 38px;
  left: 63px;
  border-bottom-color: #fff;
  border-top-width: 0;
  content: " ";
  position: absolute;
  display: block;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  border-top-width: 0;
  border-bottom-color: #fff;
  border-width: 6px;
  filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
  z-index: 120;
}

.select-item {
  &:hover {
    background: #f5f7fa;
    cursor: pointer;
  }
}

.input-pad {
  padding: 5px 0;
}
</style>
